package rpg.core
{
	import flash.display.BlendMode;
	import flash.geom.ColorTransform;

	import rpg.Utils.GameUtils;
	import rpg.render.RenderData;
	import rpg.role.SceneObject;

	public class RenderComponent extends FrameComponent
	{
		protected var sceneObj : SceneObject;

		public var render : RenderData = new RenderData();
		/**
		 *  是否允许鼠标
		 */
		public var mouseEnabled : Boolean = true;

		/**
		 * 偏移x,y坐标
		 */
		public var offsetX : int;
		public var offsetY : int;

		private var _visible : Boolean;

		public function RenderComponent(type : *)
		{
			super(type == null ? RenderComponent : type);
		}

		override public function notifyAdded() : void
		{
			sceneObj = owner as SceneObject;
		}

		public function set blendMode(blendMode : String) : void
		{
			if(render)
				render.blendMode = blendMode ? blendMode : BlendMode.NORMAL;
		}

		public function set filters(value : Array) : void
		{
			if(render)
				render.filters = value;
		}

		public function set colorTransform(value : ColorTransform) : void
		{
			if(render)
				render.colorTransform = value;
		}

		override public function update(delay : uint) : void
		{
			updateRender(sceneObj.mapX - GameUtils.viewX , sceneObj.mapY - GameUtils.viewY , offsetX , offsetY);
		}

		public function updateRender(sceneX : int , sceneY : int , offsetX : int = 0 , offsetY : int = 0) : void
		{

		}

		/**
		 * 是否可见
		 * @return
		 *
		 */
		public function get visible() : Boolean
		{
			return _visible;
		}

		public function set visible(value : Boolean) : void
		{
			_visible = value;
			if(render)
				render.visible = _visible;
		}

		public function set alpha(value : Number) : void
		{
			if(render)
				render.alpha = value;
		}

		override public function destroy() : void
		{
			super.destroy();
			sceneObj = null;
			if(render)
				render.destory();
			render = null;
		}

	}
}